package org.tacademy.and12.zlistview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ItemView extends LinearLayout {
	
	ImageView icon;
	TextView name;
	TextView phone;
	MyData mData;
	
	OnImageClickListener mListener;
	public interface OnImageClickListener{
		public void onImageClick(MyData mData);
	}
	
	public void setOnImageClickListener(MyAdapter myAdapter){
		mListener = myAdapter;
	}

	public ItemView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		
		LayoutInflater inflater = LayoutInflater.from(context);
		inflater.inflate(R.layout.itme_layout, this);
		
		icon = (ImageView) findViewById(R.id.icon);
		name = (TextView) findViewById(R.id.name);
		phone = (TextView) findViewById(R.id.phone);
		
		icon.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mListener != null){
					mListener.onImageClick(mData);
				}
			}
		});
		
		
	}
	
	public void setData(MyData data){
		mData = data;
		icon.setImageResource(data.imageId);
		name.setText(data.name);
		phone.setText(data.phone);
		
	}

}
